//
//  DemandAndServiceSearchView.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/12/17.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "DemandAndServiceSearchView.h"
@interface DemandAndServiceSearchView()
@property(nonatomic,strong) UIButton *searchBtn;
@property(nonatomic,strong) UIButton *msgBtn;
@end
@implementation DemandAndServiceSearchView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.msgBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, kHeight)];
        self.msgBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
        self.msgBtn.tag = 0;
        //        self.msgBtn.backgroundColor = [UIColor blueColor];
        [self.msgBtn setImage:[UIImage imageNamed:@"icon_86"] forState:UIControlStateNormal];
        self.msgBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.msgBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.msgBtn];
        self.searchBtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.msgBtn.frame), 0, kWidth*0.8, kHeight)];
        self.searchBtn.backgroundColor = kBg;
        self.searchBtn.tag = 1;
//        self.searchBtn.backgroundColor = [UIColor whiteColor];
        [self.searchBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        self.searchBtn.layer.masksToBounds = YES;
        self.searchBtn.layer.cornerRadius = 3;
        [self addSubview:self.searchBtn];
        [self.searchBtn setTitle:@"请输入关键词进行搜索" forState:UIControlStateNormal];
        self.searchBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
        self.searchBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(self.searchBtn.frame.size.width/2-13-20), 0, 0);
        [self.searchBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
        self.searchBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.msgBtn.frame)+10, (kHeight-13)/2, 13, 13)];
        iv.image = [UIImage imageNamed:@"icon_18"];
        [self addSubview:iv];
        
        
    }
    return self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//    if (self.returnValueBlock) {
//        self.returnValueBlock(2, self.tf.text);
//    };
    NSLog(@"点击了搜索");
    return YES;
}
-(void)clickBtn:(UIButton *)clickBtn
{
    if (self.returnValueBlock) {
        self.returnValueBlock(clickBtn.tag);
    };
}

@end
